#!/usr/bin/env node
const fsx = require('fs-extra')
const { resolve } = require('path')
const { fanyi } = require('./src/fanyi')
const args = require('yargs/yargs')(process.argv.slice(2)).argv

console.log(args)

if (args._.length && fsx.existsSync(resolve(args._[0]))) {
  const content = fsx.readFileSync(args._[0])
  const from = args.from || 'en'
  const to = args.to || 'zh'

  fanyi(content.toString(), from, to)
    .then(result => {
      console.log(`result`, result)
    })
} else {
  console.log(`File not found!`)
}

// { _: [ '/path/to/file' ], from: 'en', to: 'cn', '$0': 'index.js' }
